package cn.itsource.pet.service.impl;

import cn.itsource.pet.domain.Pet;
import cn.itsource.pet.mapper.PetDetailMapper;
import cn.itsource.pet.mapper.PetMapper;
import cn.itsource.pet.service.IPetService;
import cn.itsource.basic.base.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author huang
 * @since 2022-07-18
 */
@Service
public class PetServiceImpl extends BaseServiceImpl<Pet> implements IPetService {

    @Autowired
    private PetMapper petMapper;
    @Autowired
    private PetDetailMapper petDetailMapper;

    @Override
    @Transactional
    public void add(Pet pet) {
        //先保存宠物基本信息
        pet.setState(0L);
        pet.setCreatetime(new Date());
        petMapper.insert(pet);
        //再保存详情
        pet.getDetail().setPetId(pet.getId());
        petDetailMapper.insert(pet.getDetail());
    }
}
